#pragma once
#include <d3d9.h>
#include <d3dx9.h>
#include <dxerr.h>
#include "Graphics.h"
#include "WorldPosition.h"
#include <fstream>


namespace Renderer
{
	class Object
	{
		static std::ofstream test;
	protected:
		Graphics * graphics;
		Mesh * mesh;
		sAnimationSet * animationSet;
		WorldPosition pos;

		bool	isBillboard;
		ULONG	startTime;

		void UpdateFrame(sFrame * frame, D3DXMATRIX * Matrix, int test);
		void DrawFrame(sFrame * frame);
		void DrawMesh(sMesh * mesh);
		

	public:
		Object();
		~Object();

		bool Create(Graphics * graphics, Mesh * mesh = NULL);
		void Free();

		void EnableBillboard(bool enable = true);
		bool AttachToObject(Object * object, char * frameName = NULL);

		void Move(float posX, float posY, float posZ);
		void MoveRel(float addX, float addY, float addZ);

		void Rotate(float rotX, float rotY, float rotZ);
		void RotateRel(float addX, float addY, float addZ);

		void Scale(float scaleX, float scaleY, float scaleZ);
		void ScaleRel(float addX, float addY, float addZ);

		D3DXMATRIX * GetMatrix();

		float GetPosX();
		float GetPosY();
		float GetPosZ();
		float GetRotX();
		float GetRotY();
		float GetRotZ();
		float GetScaleX();
		float GetScaleY();
		float GetScaleZ();

		bool GetBounds(float * minX, float * minY, float * minZ, float * maxX, float * maxY, float * maxZ, float * radius);

		void SetMesh(Mesh * mesh);
		Mesh* GetMesh();

		void SetAnimation(Animation * animation, char * name = NULL, ULONG startTime = 0);
		char * GetAnimationName();

		void ResetAnimation(ULONG startTime = 0);

		void UpdateAnimation(ULONG time, bool smooth = true);
		bool AnimationComplete(ULONG time);

		void Update();
		bool Render();
	};
}